/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.tarena.lbs.attach.controller;

import com.tarena.lbs.attach.pojo.dto.AttachDTO;
import com.tarena.lbs.attach.pojo.dto.AttachQrDTO;
import com.tarena.lbs.attach.pojo.param.AttachQRParam;
import com.tarena.lbs.attach.pojo.param.PicUpdateParam;
import com.tarena.lbs.attach.pojo.query.AttachQuery;
import com.tarena.lbs.attach.service.AttachService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/attach")
public class AttachController {

    @Autowired
    private AttachService attachService;

    @PostMapping("/query")
    public List<AttachDTO> getAttachInfo(@RequestBody AttachQuery attachQuery) {
        return attachService.getAttachInfo(attachQuery);
    }

    @PostMapping("/batch-update-business")
    public boolean batchUpdateBusiness(@RequestBody List<PicUpdateParam> picParams) {
        return attachService.batchUpdateBusiness(picParams);
    }

    @PostMapping("/generate-qr")
    public AttachQrDTO generateQrCode(@RequestBody AttachQRParam attachQRParam) {
        return attachService.generateQrCode(attachQRParam);
    }

    @PostMapping("/bind-business-pics")
    public boolean bindBusinessPics(@RequestBody List<PicUpdateParam> picParams) {
        return attachService.bindBusinessPics(picParams);
    }

    @PostMapping("/bind-activity-pics")
    public boolean bindActivityPics(@RequestBody List<PicUpdateParam> picParams) {
        return attachService.bindActivityPics(picParams);
    }

    @PostMapping("/bind-content-pics")
    public boolean bindContentPics(@RequestBody List<PicUpdateParam> picParams) {
        return attachService.bindContentPics(picParams);
    }

    @PostMapping("/generate-coupon-qr")
    public AttachQrDTO generateCouponQrCode(@RequestBody AttachQRParam attachQRParam) {
        return attachService.generateCouponQrCode(attachQRParam);
    }

    @DeleteMapping("/delete-pics")
    public boolean deleteAttachPics(@RequestBody List<Integer> attachIds) {
        return attachService.deleteAttachPics(attachIds);
    }

    @DeleteMapping("/delete-by-business")
    public boolean deletePicsByBusiness(
            @RequestParam String businessId,
            @RequestParam String businessType) {
        return attachService.deletePicsByBusiness(businessId, businessType);
    }
}
